package app.web.cartoon.collect;

import app.common.dao.Leo_can_detail_infoBean;
import app.common.dao.Leo_can_infoBean;
import app.common.dao.Leo_res_infoBean;
import app.esb.cartoon.CartoonExcutor;
import app.esb.common.FileTools;
import app.esb.common.NumberTools;
import app.esb.disk.DiskExcutor;
import app.esb.res.ResExcutor;
import app.esb.tags.TagExcutor;
import cn.lily.com.component.widget.standard.TWForm;
import cn.lily.com.db.DBFactory;
import cn.lily.com.db.container.reader.DataTable;
import cn.lily.com.db.sql.DBManager;
import cn.lily.com.exception.YaconException;
import cn.lily.com.lang.BusinessDate;
import cn.lily.esb.enums.EnumManager;
import cn.lily.web.page.BusinessPage;
import cn.lily.web.widget.sql.TSqlGrid;
import cn.lily.web.widget.standard.TButton;
import cn.lily.web.widget.standard.TButtonPilot;
import cn.lily.web.widget.standard.TDrop;
import cn.lily.web.widget.standard.TInput;
/**
 * 动漫采集页面
 * @author JiaJ
 * @date 2017年12月2日
 *
 */
public class CartoonCollect extends BusinessPage {

	@Override
	public void page_onLoad() throws YaconException {
		
		//主表
		this.mainTable();
		
		//从表
		this.appTable();
		
	}
	
	 /**
	  * 主表装载
	  */
	 public void mainTable(){
		 
		 TSqlGrid cartoonMainGrid = sqlGrid("cartoonMainGrid");
		 
		 cartoonMainGrid.setDictTable("LEO_CAN_INFO");
		 String sqlString = "select CAN_ID,CAN_NAME,CAN_NAM_JAP,"
						 		 + "CAN_NAM_ENG,CAN_AREA,CAN_SOURCE,CAN_TOTAL,"
						 		 + "CAN_DEMO,CAN_SIZE,to_char(CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') CREATE_TIME,"
						 		 + "to_char(UPDATE_TIME,'yyyy-mm-dd hh24:mi:ss') UPDATE_TIME,CAN_NAME_MEMO,"
						 		 + "CAN_NAME_OTHER,CAN_FIRST "
		 		          + "from ${schema}.LEO_CAN_INFO "
		 		          + "order by CREATE_TIME DESC ";
		 
		 cartoonMainGrid.setCommSqlStr(sqlString);
		 cartoonMainGrid.setEdit(true);
		 cartoonMainGrid.setExcuteMethod("save");
		 cartoonMainGrid.setRefreshMethod("refresh");

		 cartoonMainGrid.createFieldTitle("CAN_NAME").setDataAlign("center");
		 cartoonMainGrid.createFieldTitle("CAN_NAME_OTHER").setDataAlign("center");
		 cartoonMainGrid.createFieldTitle("CAN_SIZE").setDataAlign("center");
		 cartoonMainGrid.createFieldTitle("CAN_SOURCE").setDataAlign("center");
		 cartoonMainGrid.createFieldTitle("CAN_AREA").setDataAlign("center");
		 cartoonMainGrid.createFieldTitle("CAN_DEMO").setFieldVisible(false);
		 cartoonMainGrid.createFieldTitle("CAN_TOTAL").setFieldVisible(false);
		 cartoonMainGrid.createFieldTitle("CAN_FIRST").setFieldVisible(false);
		 cartoonMainGrid.createFieldTitle("CAN_ID").setFieldVisible(false);	 
		 cartoonMainGrid.createFieldTitle("CAN_NAME_MEMO").setFieldVisible(false);		 
		 cartoonMainGrid.createFieldTitle("CAN_NAM_ENG").setFieldVisible(false);
		 cartoonMainGrid.createFieldTitle("CAN_NAM_JAP").setFieldVisible(false);
		 cartoonMainGrid.createFieldTitle("CREATE_TIME").setFieldVisible(false);
		 cartoonMainGrid.createFieldTitle("UPDATE_TIME").setFieldVisible(false);

		 cartoonMainGrid.detailPage().setPagePath("cartoonMainEdit.jsp");
		 
		 TButtonPilot cartoonMainPilot = ButtonPilot("cartoonMainPilot");
		 cartoonMainPilot.setPilotIco("glyphicon glyphicon-pushpin");
		 cartoonMainPilot.setPilotText("动漫基本信息");

		 TButton addButton = new TButton("add");
		 TButton editButton = new TButton("edit");
		 TButton delButton = new TButton("delete");
		 cartoonMainPilot.addButtons(addButton);
		 cartoonMainPilot.addButtons(editButton);
		 cartoonMainPilot.addButtons(delButton);
		 
		 cartoonMainPilot.addButtons(new TButton("refresh"));
		 
		 this.setFindForm(cartoonMainGrid.createFindForm());
		 
		 //展示全部信息
		 cartoonMainGrid.setTopButtonType("all");

		 cartoonMainGrid.setButtonPilot(cartoonMainPilot);
		 getPage().addElement(cartoonMainGrid);
		 
	 }
	 
	 /**
	  * 主表刷新
	  * @throws YaconException
	  */
	 public void refresh() throws YaconException {

		 TSqlGrid cartoonMainGrid = sqlGrid("cartoonMainGrid");
		 String sqlString = "select CAN_ID,CAN_NAME,CAN_NAM_JAP,"
						 		 + "CAN_NAM_ENG,CAN_AREA,CAN_SOURCE,CAN_TOTAL,"
						 		 + "CAN_DEMO,CAN_SIZE,to_char(CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') CREATE_TIME,"
						 		 + "to_char(UPDATE_TIME,'yyyy-mm-dd hh24:mi:ss') UPDATE_TIME,CAN_NAME_MEMO,"
						 		 + "CAN_NAME_OTHER,CAN_FIRST "
				          + "from ${schema}.LEO_CAN_INFO "
				          + "where 1=1 "
				          + this.setWhereSQL() 
				          + " order by CREATE_TIME DESC ";
		 cartoonMainGrid.setCommSqlStr(sqlString);
		 this.setSelfMessage(cartoonMainGrid.getDataElement());

	 }
	 
	 /**
	  * 主表执行方法
	  * @throws YaconException
	  */
	 public void save() throws YaconException {
		 			
		 Leo_can_infoBean cartoonMainBean = new Leo_can_infoBean();
		 while (getViewTable().next()) {
			 
			 cartoonMainBean.setViewRecord(getViewTable().getRecord());
			 cartoonMainBean.setCan_demo(this.getViewTable().getString("CAN_DEMO"));

			 if (getViewTable().getRecord().getRecordType() == 1) {
				 
				 if(CartoonExcutor.checkCartoonName(this.getViewTable().getRecord())){
					 throw new YaconException("名称信息已经存在！");
				 }
				 
				 String canID = this.getDBSequence().getBussSeq("leo_can_id", 8);
				 
				 //设置动漫标示
				 cartoonMainBean.setCan_id(canID);
				 
				 //名称处理
				 CartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAME"), canID);
				 CartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_ENG"), canID);
				 CartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_JAP"), canID);
				 
				 cartoonMainBean.setCan_total("0"); //番数
				 cartoonMainBean.setCan_size("0MB"); //动漫总体积
				 cartoonMainBean.setUpdate_time(BusinessDate.getTodaytime());  //更新时间
				 cartoonMainBean.setCreate_time(BusinessDate.getTodaytime());  //添加时间
				 
				 //名称后续处理
				 cartoonMainBean.setCan_name_other(CartoonExcutor.getCartoonOtherName(this.getViewTable().getRecord()));
				 cartoonMainBean.setCan_name_memo(CartoonExcutor.getCartoonAllName(this.getViewTable().getRecord()));
				 
				 //动漫关联信息
				 CartoonExcutor.instCartoonRela(canID);
				 
				 cartoonMainBean.insert();
				 
			 }
			 
			 else if (getViewTable().getRecord().getRecordType() == 2) {
				 
				 cartoonMainBean.setUpdate_time(BusinessDate.getTodaytime());
				 
				 String canID = getViewTable().getString("CAN_ID");
								 
				 //名称信息删除
				 this.dataRelaDelete("LEO_CAN_NAME", "CAN_ID");
				 
				 //校验名称
				 if( CartoonExcutor.checkCartoonName(this.getViewTable().getRecord())){
					 throw new YaconException("名称信息已经存在！");
				 }
				 
				 //名称处理
				 CartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAME"), canID);
				 CartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_ENG"), canID);
				 CartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_JAP"), canID);
				 
				 //名称后续处理
				 cartoonMainBean.setCan_name_other(CartoonExcutor.getCartoonOtherName(this.getViewTable().getRecord()));
				 cartoonMainBean.setCan_name_memo(CartoonExcutor.getCartoonAllName(this.getViewTable().getRecord()));
					 
				 cartoonMainBean.updateByWhere("where CAN_ID='"+getViewTable().getString("CAN_ID")+"'");
			 }

			 else if (getViewTable().getRecord().getRecordType() == 3) {
				 
				 //明细信息处理
				 this.dataRelaException("LEO_CAN_DETAIL_INFO", "CAN_ID", "动漫下存在明细信息，请先进行删除！");
				 
				 //名称信息删除
				 this.dataRelaDelete("LEO_CAN_NAME", "CAN_ID");
				 //关联信息删除
				 this.dataRelaDelete("LEO_CAN_ANY_RELA","CAN_ID");
				 		 
				 cartoonMainBean.deleteByWhere("where CAN_ID='"+getViewTable().getString("CAN_ID")+"'");
			 }

		 }
		 
		 this.setSuccess("数据操作成功！");
 
	 }
	 
	 /**
	  * 从表
	  */
	 public void appTable(){
		 
		 TSqlGrid cartoonDetailGrid = sqlGrid("cartoonDetailGrid");
		 
		 cartoonDetailGrid.setDictTable("LEO_CAN_DETAIL_INFO,LEO_RES_INFO,LEO_CAN_TIME");
		 cartoonDetailGrid.setEdit(true);
		 cartoonDetailGrid.setExcuteMethod("fsave");
		 cartoonDetailGrid.setRefreshMethod("frefresh");

		 
		 cartoonDetailGrid.createFieldTitle("CAN_DETAIL_NAME");
		 cartoonDetailGrid.createFieldTitle("CAN_QUA");
		 cartoonDetailGrid.createFieldTitle("CAN_STAT");
		 cartoonDetailGrid.createFieldTitle("CAN_KIND");
		 cartoonDetailGrid.createFieldTitle("CAN_TIME").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("CAN_FANS");
		 cartoonDetailGrid.createFieldTitle("CAN_TOTAL");
		 cartoonDetailGrid.createFieldTitle("CAN_TYP_MEMO");
		 cartoonDetailGrid.createFieldTitle("RES_STORE_SIZE");
		 cartoonDetailGrid.createFieldTitle("DISK_ID");
		 cartoonDetailGrid.createFieldTitle("RES_STORE_PLACE");
		 
		 cartoonDetailGrid.createFieldTitle("CAN_DEMO").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("CAN_DETAIL_ID").setFieldVisible(false);	 
		 cartoonDetailGrid.createFieldTitle("CAN_FIRM_MEMO").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("CAN_ID").setFieldVisible(false);		 
		 
		 cartoonDetailGrid.createFieldTitle("RES_ID").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("RES_NAM").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("RES_TYP").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("RES_TIME").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("RES_OPER").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("RES_MEMO").setFieldVisible(false);	 
		 cartoonDetailGrid.createFieldTitle("RES_TAG_MEMO").setFieldVisible(false);
		 
		 cartoonDetailGrid.createFieldTitle("CAN_NAME").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("CAN_NAM_ENG").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("CAN_NAM_JAP").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("CAN_FIRST").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("CAN_AREA").setFieldVisible(false);
		 cartoonDetailGrid.createFieldTitle("CAN_SOURCE").setFieldVisible(false);
		 
		 cartoonDetailGrid.createFieldTitle("CAN_TIME_FIX").setFieldVisible(false);

		 cartoonDetailGrid.masterTable().setMasterID("cartoonMainGrid").addForeignField("CAN_ID", "CAN_ID");
		 cartoonDetailGrid.detailPage().setPagePath("cartoonDetailEdit.jsp");
		 

		 TButtonPilot cartoonDetailPilot = ButtonPilot("cartoonDetailPilot");
		 cartoonDetailPilot.setPilotIco("glyphicon glyphicon-pushpin");
		 cartoonDetailPilot.setPilotText("动漫明细信息");

		 TButton addButton = new TButton("add");
		 TButton editButton = new TButton("edit");
		 TButton delButton = new TButton("delete");
		 cartoonDetailPilot.addButtons(addButton);
		 cartoonDetailPilot.addButtons(editButton);
		 cartoonDetailPilot.addButtons(delButton);

		 cartoonDetailGrid.setButtonPilot(cartoonDetailPilot);
		 
		 cartoonDetailGrid.setTopButtonType("all");
		 
		 getPage().addElementRow(cartoonDetailGrid);
		 
	 }
	 
	 /**
	  * 从表刷新
	  */
	 public void frefresh(){
		 
		 String canID = this.getViewTable().getAttributeValue("CAN_ID");

		 TSqlGrid cartoonDetailGrid = sqlGrid("cartoonDetailGrid");
		 String sqlString = "select li.RES_ID,li.CAN_DETAIL_ID,li.CAN_ID,li.CAN_DETAIL_NAME,"
						 		 + "li.CAN_QUA,li.CAN_KIND,li.CAN_STAT,li.CAN_TOTAL,"
						 		 + "to_char(li.CAN_TIME,'yyyy-mm-dd hh24:mi:ss') CAN_TIME,"
						 		 + "li.CAN_DEMO,li.CAN_FIRM_MEMO,li.CAN_TYP_MEMO,"
				                 + "lr.RES_NAM,lr.RES_TYP,"
				                 + "lr.RES_STORE_SIZE,lr.RES_STORE_PLACE,"
				                 + "to_char(lr.RES_TIME,'yyyy-mm-dd hh24:mi:ss') RES_TIME,"
				                 + "lr.RES_OPER,lr.RES_MEMO,lr.DISK_ID,lr.RES_TAG_MEMO,"
				                 + "lt.CAN_FANS,"
				                 + "lci.CAN_NAME,lci.CAN_NAM_ENG,lci.CAN_NAM_JAP,"
				                 + "lci.CAN_FIRST,lci.CAN_AREA,lci.CAN_SOURCE,"
				                 + "to_char(li.CAN_TIME,'yyyy-mm-dd') CAN_TIME_FIX "
						  + "from ${schema}.LEO_CAN_DETAIL_INFO li "
						  + "left join ${schema}.LEO_RES_INFO lr on li.RES_ID=lr.RES_ID "
						  + "left join ${schema}.LEO_CAN_TIME lt on li.CAN_DETAIL_ID=lt.CAN_DETAIL_ID "
						  + "inner join ${schema}.LEO_CAN_INFO lci on li.CAN_ID=lci.CAN_ID "
						  + "where li.CAN_ID='"+canID+"' "
						  + " order by CAN_TIME desc";
		 
		 cartoonDetailGrid.setCommSqlStr(sqlString);
		 
		 this.setSelfMessage(cartoonDetailGrid.getDataElement());
		 
	 }
	 
	 /**
	  * 从表执行
	  */
	 public void fsave(){
		 
		//主表Bean
		 Leo_can_infoBean cartoonMainBean = new Leo_can_infoBean();
		 //从表Bean
		 Leo_can_detail_infoBean cartoonDetailBean = new Leo_can_detail_infoBean();
		 //资源Bean
		 Leo_res_infoBean resBean = new Leo_res_infoBean();
		 
		 while (getViewTable().next()) {
			 
			 String canID = this.getViewTable().getAttributeValue("CAN_ID");
			 
			 cartoonDetailBean.setViewRecord(getViewTable().getRecord());
			 cartoonMainBean.setViewRecord(getViewTable().getRecord());
			 resBean.setViewRecord(getViewTable().getRecord());
			 
			 cartoonDetailBean.setCan_demo(this.getViewTable().getString("CAN_DEMO"));

			 if (getViewTable().getRecord().getRecordType() == 1) {
				 
				 String isInst = this.getViewTable().getString("INST_DROP");
				 
				 this.dataExistCommon(cartoonDetailBean, "CAN_DETAIL_NAME", "该明细信息已经维护过！");
				 
				 cartoonDetailBean.setCan_id(canID);
				 
				 //主键信息
				 String canDetailID = this.getDBSequence().getBussSeq("leo_can_detail_id", 8);
				 cartoonDetailBean.setCan_detail_id(canDetailID);				 
				 
				 String resID = this.getDBSequence().getBussSeq("leo_res_id", 8);
				 cartoonDetailBean.setRes_id(resID);
				 resBean.setRes_id(resID);
				 
				 //普通类型
				 if("0".equals(isInst)){
					 
					 //从表信息插入
					 this.insertDetailTable(cartoonDetailBean,canID);
					 
					 //资源信息插入
					 this.insertRes(resBean,canID);
					 
					 //更新主表的汇总信息
					 this.updateMainTable(canID);
					
				 }
				 
				 //自建类型
				 else if("1".equals(isInst)){
					 
					 //磁盘体积添加
					 String size = this.getViewTable().getString("RES_STORE_SIZE");
					 if("".equals(size) || size == null){
						 size = FileTools.getFileSize(this.getViewTable().getString("RES_STORE_PLACE"));
					 }
					 
					 //生成主表标示
					 canID = this.getDBSequence().getBussSeq("leo_can_id", 8);					 
					 this.getViewTable().setFieldValue("CAN_ID", canID);
					 
					 //设置动漫标示
					 cartoonMainBean.setCan_id(canID);					 
					 cartoonMainBean.setCan_size(size);
					 cartoonMainBean.setCan_total("1");
					 
					 this.insertMainTable(cartoonMainBean,canID);
		 
					 //从表信息插入
					 cartoonDetailBean.setCan_id(canID);
					 this.insertDetailTable(cartoonDetailBean,canID);
					 
					 //资源信息插入
					 this.insertRes(resBean,canID);
					 
				 }
				 	 
			 }
			 
			 else if (getViewTable().getRecord().getRecordType() == 2) {
				 
				 canID = this.getViewTable().getString("CAN_ID");
				 String canDetailID = this.getViewTable().getString("CAN_DETAIL_ID");
				 String resID = this.getViewTable().getString("RES_ID");
				 
				 //上市时间
				 String time = this.getViewTable().getString("CAN_TIME_FIX");
				 time = BusinessDate.formatDate(time);
				 
				 //时间处理
				 CartoonExcutor.delCartoonTime(canDetailID);
				 CartoonExcutor.insertCartoonTime(time, canDetailID);
				 
				 //类型处理
				 String type = this.getViewTable().getString("CAN_TYP_MEMO");
				 CartoonExcutor.delCartoonType(canDetailID);
				 CartoonExcutor.insertCartoonType(type, canDetailID);
				 
				 //厂商处理
				 String firm = this.getViewTable().getString("CAN_FIRM_MEMO");
				 CartoonExcutor.delCartoonFirms(canDetailID);
				 CartoonExcutor.insertCartoonFirms(firm, canDetailID);
				 
				 cartoonDetailBean.setCan_time(time+" 00:00:00");
				 cartoonDetailBean.updateByWhere("where CAN_DETAIL_ID='"+getViewTable().getString("CAN_DETAIL_ID")+"'");
				 
				 //磁盘信息去除
				 ResExcutor.delResDisk(resID);
				 
				 //资源信息处理
				 String editResSql =  "update LEO_RES_INFO "
							 		+ "set RES_NAM='"+this.getViewTable().getString("CAN_DETAIL_NAME")+"',"
							 		    + "RES_STORE_SIZE='"+this.getViewTable().getString("RES_STORE_SIZE")+"',"
							 			+ "RES_STORE_PLACE='"+FileTools.getRelaLocation(this.getViewTable().getString("RES_STORE_PLACE"))+"',"
							 			+ "DISK_ID='"+this.getViewTable().getString("DISK_ID")+"',"
							 			+ "RES_TAG_MEMO='"+this.getViewTable().getString("RES_TAG_MEMO")+"' "
							 		+ "where RES_ID='"+resID+"'";
				 
				 this.getDBManager().executeUpdate(editResSql);
				 
				 //磁盘信息添加
				 DiskExcutor dex = new DiskExcutor(this.getViewTable().getString("DISK_ID"));
				 dex.addSize(this.getViewTable().getString("RES_STORE_SIZE"));
				 dex.excute();
				 
				 //标签信息处理
				 String tags = this.getViewTable().getString("RES_TAG_MEMO");
				 TagExcutor.delTags(resID);
				 TagExcutor.insertTags(tags, resID);
				 
				 this.updateMainTable(canID);
				 
			 }	 

			 else if (getViewTable().getRecord().getRecordType() == 3) {
				 
				 String resID = this.getViewTable().getString("RES_ID");
				 
				 //授权表清除
				 this.dataRelaDelete("LEO_CAN_TIME", "CAN_DETAIL_ID");
				 this.dataRelaDelete("LEO_CAN_FIRM_RELA", "CAN_DETAIL_ID");
				 this.dataRelaDelete("LEO_CAN_TYP_RELA", "CAN_DETAIL_ID");
				 
				 //数据处理				 
				 ResExcutor.delResDisk(resID);
				 
				 //资源表清除
				 this.dataRelaDelete("LEO_RES_INFO", "RES_ID");
				 this.dataRelaDelete("LEO_TAG_RELA", "RES_ID");
				 
				 cartoonDetailBean.deleteByWhere("where CAN_DETAIL_ID='"+getViewTable().getString("CAN_DETAIL_ID")+"'");
				 
				 //更新主表
				 this.updateMainTable(canID);
				 
			 }

		 }
		 this.setSuccess("数据操作成功！");
		 
	 }
	 
	 /**
	  * 插入从表信息
	  * @param cartoonDetailBean
	  */
	 public void insertDetailTable(Leo_can_detail_infoBean cartoonDetailBean,String canID){
		 
		 String canDetailID = cartoonDetailBean.getCan_detail_id();
		 
		 //上市时间
		 String time = this.getViewTable().getString("CAN_TIME_FIX");
		 time = BusinessDate.formatDate(time);
		 cartoonDetailBean.setCan_time(time+" 00:00:00");
		 
		 //类型
		 String type = this.getViewTable().getString("CAN_TYP_MEMO");
		 if(type == null || "".equals(type)){
			 type = CartoonExcutor.getCartoonTyps(canID);
		 }
		 cartoonDetailBean.setCan_typ_memo(type);
		 	 
		 //厂商
		 String firm = this.getViewTable().getString("CAN_FIRM_MEMO");
		 if(firm == null || "".equals(firm)){
			 firm = CartoonExcutor.getCartoonFirms(canID);
		 }
		 cartoonDetailBean.setCan_firm_memo(firm);
		 
		 //简介
		 String memo = this.getViewTable().getString("CAN_DEMO");
		 if(memo == null || "".equals(memo)){
			 memo = CartoonExcutor.getCartoonMemos(canID);
		 }
		 cartoonDetailBean.setCan_demo(memo);
		 
		 cartoonDetailBean.insert();
		 
		 //时间处理
		 CartoonExcutor.insertCartoonTime(time, canDetailID);
		  
		 //类型处理	 
		 CartoonExcutor.insertCartoonType(type, canDetailID);
		 
		 //厂商处理 
		 CartoonExcutor.insertCartoonFirms(firm, canDetailID);
	 }
	 
	 /**
	  * 资源信息插入
	  * @param resBean
	  */
	 public void insertRes(Leo_res_infoBean resBean,String canID){
		 
		 String resID = resBean.getRes_id();

		 resBean.setRes_nam(this.getViewTable().getString("CAN_DETAIL_NAME"));
		 resBean.setRes_typ("01");		 
		 resBean.setRes_oper(this.getOperator().getOperId());
		 resBean.setRes_time(BusinessDate.getTodaytime());
		 resBean.setRes_memo(this.getViewTable().getString("RES_MEMO"));
		 resBean.setRes_store_place(FileTools.getRelaLocation(this.getViewTable().getString("RES_STORE_PLACE")));
		 		 
		 //磁盘体积添加
		 String size = this.getViewTable().getString("RES_STORE_SIZE");
		 if("".equals(size) || size == null){
			 size = FileTools.getFileSize(this.getViewTable().getString("RES_STORE_PLACE"));
		 }
		 
		 resBean.setRes_store_size(size);
		 
		 //标签信息处理
		 String tags = this.getViewTable().getString("RES_TAG_MEMO");
		 if(tags == null || "".equals(tags)){
			 tags = TagExcutor.getTags(canID);
		 }
		 if(tags == null || "".equals(tags)){
			 tags = this.getViewTable().getString("CAN_TYP_MEMO");
		 }
		 
		 resBean.setRes_tag_memo(tags);
		 
		 resBean.insert();
		 
		 //磁盘信息处理
		 DiskExcutor de = new DiskExcutor(this.getViewTable().getString("DISK_ID"));
		 de.addSize(size);
		 de.excute();
		 
		 //标签信息处理	 
		 TagExcutor.insertTags(tags, resID);
	 }
	 
	 /**
	  * 主表插入
	  * @param cartoonMainBean
	  */
	 public void insertMainTable(Leo_can_infoBean cartoonMainBean,String canID){
		 
		 if(CartoonExcutor.checkCartoonName(this.getViewTable().getRecord())){
			 throw new YaconException("名称信息已经存在！");
		 }
		 
		 //名称处理
		 CartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAME"), canID);
		 CartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_ENG"), canID);
		 CartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_JAP"), canID);
		 
		 cartoonMainBean.setUpdate_time(BusinessDate.getTodaytime());  //更新时间
		 cartoonMainBean.setCreate_time(BusinessDate.getTodaytime());  //添加时间
		 
		 //名称后续处理
		 cartoonMainBean.setCan_name_other(CartoonExcutor.getCartoonOtherName(this.getViewTable().getRecord()));
		 cartoonMainBean.setCan_name_memo(CartoonExcutor.getCartoonAllName(this.getViewTable().getRecord()));
		 
		 //动漫关联信息
		 CartoonExcutor.instCartoonRela(canID);
	
		 cartoonMainBean.insert();
		 
	 }
	 
	 /**
	  * 更新主表汇总信息
	  */
	 public void updateMainTable(String canID){
		 
		 String sqlString = "select li.RES_ID,li.CAN_DETAIL_ID,li.CAN_ID,li.CAN_DETAIL_NAME,"
						 		 + "li.CAN_QUA,li.CAN_KIND,li.CAN_STAT,li.CAN_TOTAL,"
						 		 + "to_char(li.CAN_TIME,'yyyy-mm-dd hh24:mi:ss') CAN_TIME,"
						 		 + "li.CAN_DEMO,li.CAN_FIRM_MEMO,li.CAN_TYP_MEMO,"
				                 + "lr.RES_NAM,lr.RES_TYP,"
				                 + "lr.RES_STORE_SIZE,lr.RES_STORE_PLACE,"
				                 + "to_char(lr.RES_TIME,'yyyy-mm-dd hh24:mi:ss') RES_TIME,"
				                 + "lr.RES_OPER,lr.RES_MEMO,lr.DISK_ID,lt.CAN_FANS "
						  + "from ${schema}.LEO_CAN_DETAIL_INFO li "
						  + "inner join ${schema}.LEO_RES_INFO lr on li.RES_ID=lr.RES_ID "
						  + "inner join ${schema}.LEO_CAN_TIME lt on lt.CAN_DETAIL_ID=li.CAN_DETAIL_ID "
						  + "where li.CAN_ID='"+canID+"'";
		 
		 DBManager dbManager = DBFactory.getActionDB();
		 DataTable dt = dbManager.executeQueryTable(sqlString);
			
		 double total = 0.00;
		 while(dt.next()){
			total = total + NumberTools.toKBSize(dt.getString("RES_STORE_SIZE"));
		 }
		 
		 this.getDBManager().executeUpdate("update ${schema}.LEO_CAN_INFO "
								 		 + "set CAN_TOTAL='"+dt.getRecordCount()+"',CAN_SIZE='"+NumberTools.toSizeString(total)+"' "
								 		 + "where CAN_ID='"+canID+"' ");
	 }
	 
		/**
		 * 查询表单
		 * @throws YaconException
		 */
		private void setFindForm(TWForm findForm) {
		
			//动漫名称
			TInput canNam = Input("canNam");
			canNam.setLabel("动漫名称");
			
			//动漫来源
			TDrop canSrc = Drop("canSrc");
			canSrc.put("", "");
			canSrc.setEnumDetail(EnumManager.getTableEnum("CAN_SOURCE"));
			canSrc.setLabel("动漫来源");
			
			//动漫地区
			TDrop canArea = Drop("canArea");
			canArea.put("", "");
			canArea.setEnumDetail(EnumManager.getTableEnum("CAN_AREA"));
			canArea.setLabel("动漫地区");
			
			//查询
			TButton find = Button("selectBtn");
			find.setIcoPath("glyphicon glyphicon-search");
			find.setViewClick("selectBtn_onclick");
			find.setLabel("查询");
			
			//重置
			TButton reset = Button("resetBtn");
			reset.setIcoPath("glyphicon glyphicon-share-alt");
			reset.setViewClick("resetBtn_onclick");
			reset.setLabel("重置");
			
			//Form排版
			findForm.createFormCell(canNam);
			findForm.createFormCell(canSrc);
			findForm.createFormCell(canArea);
			
			findForm.createFormCell(find);
			findForm.addFormCell(reset);
			
		}
		
		/**
		 * 获取条件语句（根据实际情况调整）
		 */
		public String setWhereSQL() {

			String ret = " ";

			String canNam = this.getViewTable().getAttributeValue("canNam");
			String canSrc = this.getViewTable().getAttributeValue("canSrc");
			String canArea = this.getViewTable().getAttributeValue("canArea");

			if(canNam!=null&&!"".equals(canNam)){
				ret += " and CAN_ID in (select distinct CAN_ID from ${schema}.LEO_CAN_NAME where CAN_NAME_FIX like '%"+canNam+"%' ) ";
			}
			if(canSrc!=null&&!"".equals(canSrc)){
				ret += " and CAN_SOURCE = '"+canSrc+"' ";
			}
			if(canArea!=null&&!"".equals(canArea)){
				ret += " and CAN_AREA = '"+canArea+"' ";
			}

			return ret;
			
		}

}
